﻿#region Copyright (c) 2007 Mikko Salmi, Contributors
/*
 *
 * Copyright (c) 2007 Mikko Salmi, Contributors
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
 * and associated documentation files (the "Software"), to deal in the Software without restriction, 
 * including without limitation the rights to use, copy, modify, merge, publish, distribute,
 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is 
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all copies or 
 * substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT 
 * NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 
 * 
*/
#endregion // Copyright

#region Notes
/*
 * Silverlight Slideshow Project Page:
 * http://www.codeplex.com/silverlightslideshow/  
 * 
 * 06/01/08 (YY/MM/DD) MSa: initial version
 *   
*/
#endregion // Notes

using System;
using System.Runtime.InteropServices;
using System.Web.UI;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Xml.Serialization;

using Microsoft.SharePoint;
using Microsoft.SharePoint.Navigation;
using Microsoft.SharePoint.WebPartPages;
using System.Text;

namespace CodePlex.WebParts
{
    [XmlRoot(Namespace = "CodePlex.WebParts")]
    [Guid("1F32C7C3-34DB-42bd-A4EF-973138178EF7")]
    public class SlideshowWebPart : AdvancedWebPart
    {
        const string BUTTON_PLAYPAUSE = "BUTTON_PLAYPAUSE";
        const string BUTTON_PREVNEXT = "BUTTON_PREVNEXT";
        const string BUTTON_PREVNEXTPAGE = "BUTTON_PREVNEXTPAGE";
        const string BUTTON_FULLSCREEN = "BUTTON_FULLSCREEN";
        const string BUTTON_SAVE = "BUTTON_SAVE";
        const string BUTTON_DELIMITER = " | ";

        string libraryName;


        #region Slideshow Behavior

        [Personalizable(PersonalizationScope.Shared),
        WebBrowsable,
        WebDisplayName("Library Name"),
        WebDescription("Name of the picture library with slideshow pictures."),
        SPWebCategoryName("Slideshow Behavior")]
        public string LibraryName
        {
            get
            {
                return libraryName;
            }
            set
            {
                libraryName = value;
            }
        }

        bool showPlayPauseButton = true;

        [Personalizable(PersonalizationScope.Shared),
        WebBrowsable,
        WebDisplayName("ShowPlayPauseButton"),
        WebDescription("Select this checkbox to show the Play/Pause button."),
        SPWebCategoryName("Button Show Options")]
        public bool ShowPlayPauseButton
        {
          get
          {
            return showPlayPauseButton;
          }
          set
          {
            showPlayPauseButton = value;
          }
        }

        bool showPrevNextButton = true;

        [Personalizable(PersonalizationScope.Shared),
        WebBrowsable,
        WebDisplayName("ShowPrevNextButton"),
        WebDescription("Select this checkbox to show the Prev/Next button."),
        SPWebCategoryName("Button Show Options")]
        public bool ShowPrevNextButton
        {
          get
          {
            return showPrevNextButton;
          }
          set
          {
            showPrevNextButton = value;
          }
        }

        bool showPrevNextPageButton = true;

        [Personalizable(PersonalizationScope.Shared),
        WebBrowsable,
        WebDisplayName("ShowPrevNextPageButton"),
        WebDescription("Select this checkbox to show the Prev/Next Page button."),
        SPWebCategoryName("Button Show Options")]
        public bool ShowPrevNextPageButton
        {
          get
          {
            return showPrevNextPageButton;
          }
          set
          {
            showPrevNextPageButton = value;
          }
        }

        bool showFullScreenButton = true;

        [Personalizable(PersonalizationScope.Shared),
        WebBrowsable,
        WebDisplayName("ShowFullScreenButton"),
        WebDescription("Select this checkbox to show the Fullscreen button."),
        SPWebCategoryName("Button Show Options")]
        public bool ShowFullScreenButton
        {
          get
          {
            return showFullScreenButton;
          }
          set
          {
            showFullScreenButton = value;
          }
        }

        bool showSaveButton = true;

        [Personalizable(PersonalizationScope.Shared),
        WebBrowsable,
        WebDisplayName("ShowSaveButton"),
        WebDescription("Select this checkbox to show the Save button."),
        SPWebCategoryName("Button Show Options")]
        public bool ShowSaveButton
        {
          get
          {
            return showSaveButton;
          }
          set
          {
            showSaveButton = value;
          }
        }

        private const bool autoPlayDefault = true;
        bool autoPlay = autoPlayDefault;

        [Personalizable(PersonalizationScope.Shared),
        WebBrowsable,
        WebDisplayName("AutoPlay"),
        WebDescription("Select this checkbox to auto play the slideshow and uncheck it start the slideshow manually."),
        SPWebCategoryName("Slideshow Behavior")]
        public bool AutoPlay
        {
            get
            {
                return autoPlay;
            }
            set
            {
                autoPlay = value;
            }
        }

        private const bool captionVisibleDefault = true;
        bool captionVisible = captionVisibleDefault;

        [Personalizable(PersonalizationScope.Shared),
        WebBrowsable,
        WebDisplayName("CaptionVisible"),
        WebDescription("Select this checkbox to display the caption below the image. The caption is the value of the Title column of the picture."),
        SPWebCategoryName("Slideshow Behavior")]
        public bool CaptionVisible
        {
            get
            {
                return captionVisible;
            }
            set
            {
                captionVisible = value;
            }
        }

        private const bool thumbnailsVisibleDefault = true;
        bool thumbnailsVisible = thumbnailsVisibleDefault;

        [Personalizable(PersonalizationScope.Shared),
        WebBrowsable,
        WebDisplayName("ThumbnailVisible"),
        WebDescription("Selecting this checkbox enables the thumbnail strip of the pictures below the slideshow."),
        SPWebCategoryName("Slideshow Behavior")]
        public bool ThumbnailsVisible
        {
            get
            {
                return thumbnailsVisible;
            }
            set
            {
                thumbnailsVisible = value;
            }
        }

        private const bool trackerVisibleDefault = true;
        bool trackerVisible = trackerVisibleDefault;

        [Personalizable(PersonalizationScope.Shared),
        WebBrowsable,
        WebDisplayName("TrackerVisible"),
        WebDescription("Select this check box to display the current slide number. The text is shown as \"Slide N of Total\"."),
        SPWebCategoryName("Slideshow Behavior")]
        public bool TrackerVisible
        {
            get
            {
                return trackerVisible;
            }
            set
            {
                trackerVisible = value;
            }
        }

        private const SlideshowTheme themeDefault = SlideshowTheme.THEME_NONE;
        SlideshowTheme theme = themeDefault;

        [Personalizable(PersonalizationScope.Shared),
        WebBrowsable,
        WebDisplayName("Slide Theme"),
        WebDescription("There are four styles of slideshow available with slideshow web part.  The different styles are:\r\na) THEME_NONE : As default selection, pictures are shown in a sequenced slide show\r\nb) THEME_STACK : The pictures are shown sequentially with white border and appears like stacked printed pictures scattered over a surface \r\nc) THEME_RANDOM_STACK : The pictures are shown randomly with white border and appears like stacked printed pictures scattered over a surface\r\nd) THEME_RANDOM_SLIDE : The pictures are shown in a random slide show "),
        SPWebCategoryName("Slideshow Behavior")]
        public SlideshowTheme Theme
        {
            get
            {
                return theme;
            }
            set
            {
                theme = value;
            }
        }

        private const string speedRatioDefault = "1";
        string speedRatio = speedRatioDefault;

        [Personalizable(PersonalizationScope.Shared),
        WebBrowsable,
        WebDisplayName("Speed"),
        WebDescription(""),
        SPWebCategoryName("Slideshow Behavior")]
        public string SpeedRatio
        {
            get
            {
                return speedRatio;
            }
            set
            {
                speedRatio = value;
            }
        }

        #endregion  // Slideshow Behavior

        #region Slideshow Appearance

        private const string slideshowWidthDefault = "400";
        string slideshowWidth = slideshowWidthDefault;

        [Personalizable(PersonalizationScope.Shared),
        WebBrowsable,
        WebDisplayName("Slideshow Width"),
        WebDescription("This property represents the width of slideshow in pixels. The default value is 400 pixels."),
        SPWebCategoryName("Slideshow Appearance")]
        public string SlideshowWidth
        {
            get
            {
                return slideshowWidth;
            }
            set
            {
                slideshowWidth = value;
            }
        }

        private const string slideshowHeightDefault = "400";
        string slideshowHeight = slideshowHeightDefault;

        [Personalizable(PersonalizationScope.Shared),
        WebBrowsable,
        WebDisplayName("Slideshow Height"),
        WebDescription("This property represents the height of slideshow in pixels. The default value is 400 pixels."),
        SPWebCategoryName("Slideshow Appearance")]
        public string SlideshowHeight
        {
            get
            {
                return slideshowHeight;
            }
            set
            {
                slideshowHeight = value;
            }
        }

        private const string backgroundColorDefault = "Black";
        string backgroundColor = backgroundColorDefault;

        [Personalizable(PersonalizationScope.Shared),
        WebBrowsable,
        WebDisplayName("BackgroundColor"),
        WebDescription("This property represents the background color of the webpart. The default value is Black."),
        SPWebCategoryName("Slideshow Appearance")]
        public string BackgroundColor
        {
            get
            {
                return backgroundColor;
            }
            set
            {
                backgroundColor = value;
            }
        }


        private const string buttonBackgroundDefault = "Black";
        string buttonBackground = buttonBackgroundDefault;

        [Personalizable(PersonalizationScope.Shared),
        WebBrowsable,
        WebDisplayName("ButtonBackground"),
        WebDescription("This property represents the background color of the buttons (play/pause, fullscreen etc) of the webpart."),
        SPWebCategoryName("Slideshow Appearance")]
        public string ButtonBackground
        {
            get
            {
                return buttonBackground;
            }
            set
            {
                buttonBackground = value;
            }
        }


        private const string buttonForegroundDefault = "Silver";
        string buttonForeground = buttonForegroundDefault;

        [Personalizable(PersonalizationScope.Shared),
        WebBrowsable,
        WebDisplayName("ButtonForeground"),
        WebDescription("This property represents the foreground color of the buttons (Fullscreen,Save etc) of the webpart."),
        SPWebCategoryName("Slideshow Appearance")]
        public string ButtonForeground
        {
            get
            {
                return buttonForeground;
            }
            set
            {
                buttonForeground = value;
            }
        }

        private const string buttonBorderColorDefault = "Silver";
        string buttonBorderColor = buttonBorderColorDefault;

        [Personalizable(PersonalizationScope.Shared),
        WebBrowsable,
        WebDisplayName("ButtonBorderColor"),
        WebDescription("This property represents the color of border for the buttons (play/pause, fullscreen etc) of the webpart."),
        SPWebCategoryName("Slideshow Appearance")]
        public string ButtonBorderColor
        {
            get
            {
                return buttonBorderColor;
            }
            set
            {
                buttonBorderColor = value;
            }
        }
        
        private const string buttonPlayForegroundDefault = "Red";
        string buttonPlayForeground = buttonPlayForegroundDefault;

        [Personalizable(PersonalizationScope.Shared),
        WebBrowsable,
        WebDisplayName("ButtonPlayForeground"),
        WebDescription("This property represents the foreground color of the Play/Pause button of the webpart."),
        SPWebCategoryName("Slideshow Appearance")]
        public string ButtonPlayForeground
        {
            get
            {
                return buttonPlayForeground;
            }
            set
            {
                buttonPlayForeground = value;
            }
        }

        private const string captionBackgroundDefault = "Black";
        string captionBackground = captionBackgroundDefault;

        [Personalizable(PersonalizationScope.Shared),
        WebBrowsable,
        WebDisplayName("CaptionBackground"),
        WebDescription(""),
        SPWebCategoryName("Slideshow Appearance")]
        public string CaptionBackground
        {
            get
            {
                return captionBackground;
            }
            set
            {
                captionBackground = value;
            }
        }

        private const string captionFontFamilyDefault = "Verdana";
        string captionFontFamily = captionFontFamilyDefault;

        [Personalizable(PersonalizationScope.Shared),
        WebBrowsable,
        WebDisplayName("CaptionFontFamily"),
        WebDescription("This property represents the caption’s (Title) font family, the default value is \"Verdana\"."),
        SPWebCategoryName("Slideshow Appearance")]
        public string CaptionFontFamily
        {
            get
            {
                return captionFontFamily;
            }
            set
            {
                captionFontFamily = value;
            }
        }

        private const string captionFontSizeDefault = "11";
        string captionFontSize = captionFontSizeDefault;

        [Personalizable(PersonalizationScope.Shared),
        WebBrowsable,
        WebDisplayName("CaptionFontSize"),
        WebDescription("This property represents the caption’s (Title) font size in pixels, the default value is \"11\" pixels."),
        SPWebCategoryName("Slideshow Appearance")]
        public string CaptionFontSize
        {
            get
            {
                return captionFontSize;
            }
            set
            {
                captionFontSize = value;
            }
        }

        private const FontStyle captionFontStyleDefault = FontStyle.Normal;
        FontStyle captionFontStyle = captionFontStyleDefault;

        [Personalizable(PersonalizationScope.Shared),
        WebBrowsable,
        WebDisplayName("CaptionFontStyle"),
        WebDescription("There are two font style for caption available i.e. Normal and Italic, the default being Normal."),
        SPWebCategoryName("Slideshow Appearance")]
        public FontStyle CaptionFontStyle
        {
            get
            {
                return captionFontStyle;
            }
            set
            {
                captionFontStyle = value;
            }
        }

        private const FontWeight captionFontWeightDefault = FontWeight.Normal;
        FontWeight captionFontWeight = captionFontWeightDefault;

        [Personalizable(PersonalizationScope.Shared),
        WebBrowsable,
        WebDisplayName("CaptionFontWeight"),
        WebDescription("As caption’s font weight there are ten options available i.e. Thin, ExtraLight, Light, Normal, Medium, SemiBold, Bold, ExtraBold, Black, ExtraBlack. The default value is normal."),
        SPWebCategoryName("Slideshow Appearance")]
        public FontWeight CaptionFontWeight
        {
            get
            {
                return captionFontWeight;
            }
            set
            {
                captionFontWeight = value;
            }
        }

        private const string captionOpacityDefault = ".7";
        string captionOpacity = captionOpacityDefault;

        [Personalizable(PersonalizationScope.Shared),
        WebBrowsable,
        WebDisplayName("CaptionOpacity"),
        WebDescription("This property represents the caption’s opacity on a scale of 0 to 1. The default value 0.7 ."),
        SPWebCategoryName("Slideshow Appearance")]
        public string CaptionOpacity
        {
            get
            {
                return captionOpacity;
            }
            set
            {
                captionOpacity = value;
            }
        }

        private const string contentBackgroundDefault = "Black";
        string contentBackground = contentBackgroundDefault;

        [Personalizable(PersonalizationScope.Shared),
        WebBrowsable,
        WebDisplayName("ContentBackground"),
        WebDescription("The property represents the sildeshow’s picture backgroud color. This is not the web part background color but only of the picture."),
        SPWebCategoryName("Slideshow Appearance")]
        public string ContentBackground
        {
            get
            {
                return contentBackground;
            }
            set
            {
                contentBackground = value;
            }
        }

        private const string selectedThumbnailBorderColorDefault = "Yellow";
        string selectedThumbnailBorderColor = selectedThumbnailBorderColorDefault;

        [Personalizable(PersonalizationScope.Shared),
        WebBrowsable,
        WebDisplayName("SelectedThumbnailBorderColor"),
        WebDescription("Slideshow webpart allow users to manually select a picture to start slideshow from. The selected picture thumbnail’s border color can be choosen by this property. The default value of Yellow."),
        SPWebCategoryName("Slideshow Appearance")]
        public string SelectedThumbnailBorderColor
        {
            get
            {
                return selectedThumbnailBorderColor;
            }
            set
            {
                selectedThumbnailBorderColor = value;
            }
        }

        private const string trackerForegroundDefault = "Silver";
        string trackerForeground = trackerForegroundDefault;

        [Personalizable(PersonalizationScope.Shared),
        WebBrowsable,
        WebDisplayName("TrackerForeground"),
        WebDescription("This property represents the tracker’s foreground color. The default value is silver."),
        SPWebCategoryName("Slideshow Appearance")]
        public string TrackerForeground
        {
            get
            {
                return trackerForeground;
            }
            set
            {
                trackerForeground = value;
            }
        }

        private const string trackerFontFamilyDefault = "Verdana";
        string trackerFontFamily = trackerFontFamilyDefault;

        [Personalizable(PersonalizationScope.Shared),
        WebBrowsable,
        WebDisplayName("TrackerFontFamily"),
        WebDescription("This property represents the tracker’s font family, the default value is \"Verdana\"."),
        SPWebCategoryName("Slideshow Appearance")]
        public string TrackerFontFamily
        {
            get
            {
                return trackerFontFamily;
            }
            set
            {
                trackerFontFamily = value;
            }
        }

        private const string trackerFontSizeDefault = "11";
        string trackerFontSize = trackerFontSizeDefault;

        [Personalizable(PersonalizationScope.Shared),
        WebBrowsable,
        WebDisplayName("TrackerFontSize"),
        WebDescription(""),
        SPWebCategoryName("Slideshow Appearance")]
        public string TrackerFontSize
        {
            get
            {
                return trackerFontSize;
            }
            set
            {
                trackerFontSize = value;
            }
        }

        private const FontStyle trackerFontStyleDefault = FontStyle.Normal;
        FontStyle trackerFontStyle = trackerFontStyleDefault;

        [Personalizable(PersonalizationScope.Shared),
        WebBrowsable,
        WebDisplayName("TrackerFontStyle"),
        WebDescription("There are two font style for caption available i.e. Normal and Italic, the default being Normal."),
        SPWebCategoryName("Slideshow Appearance")]
        public FontStyle TrackerFontStyle
        {
            get
            {
                return trackerFontStyle;
            }
            set
            {
                trackerFontStyle = value;
            }
        }

        private const FontWeight trackerFontWeightDefault = FontWeight.Normal;
        FontWeight trackerFontWeight = trackerFontWeightDefault;

        [Personalizable(PersonalizationScope.Shared),
        WebBrowsable,
        WebDisplayName("TrackerFontWeight"),
        WebDescription("As tracker’s font weight there are ten options available i.e. Thin, ExtraLight, Light, Normal, Medium, SemiBold, Bold, ExtraBold, Black, ExtraBlack. The default value is normal."),
        SPWebCategoryName("Slideshow Appearance")]
        public FontWeight TrackerFontWeight
        {
            get
            {
                return trackerFontWeight;
            }
            set
            {
                trackerFontWeight = value;
            }
        }

        private const string borderRadiusDefault = "8";
        string borderRadius = borderRadiusDefault;

        [Personalizable(PersonalizationScope.Shared),
        WebBrowsable,
        WebDisplayName("BorderRadius"),
        WebDescription("The curved radius of the corners of the webpart is represented by this property. The default value is 8."),
        SPWebCategoryName("Slideshow Appearance")]
        public string BorderRadius
        {
            get
            {
                return borderRadius;
            }
            set
            {
                borderRadius = value;
            }
        }

        private const string paddingDefault = "8";
        string padding = paddingDefault;

        [Personalizable(PersonalizationScope.Shared),
        WebBrowsable,
        WebDisplayName("Padding"),
        WebDescription("This property represents the padding around the picture, thumbnail strip, button strip and tracker. The default value is \"8\" pixels."),
        SPWebCategoryName("Slideshow Appearance")]
        public string Padding
        {
            get
            {
                return padding;
            }
            set
            {
                padding = value;
            }
        }

        #endregion // Slideshow Appearance

        LiteralControl div;

        public SlideshowWebPart()
        {
            this.ExportMode = WebPartExportMode.All;
        }

        protected override void CreateChildControls()
        {
            base.CreateChildControls();
        }

        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);

            if (!string.IsNullOrEmpty(this.LibraryName))
            {
                div = new LiteralControl();
                this.Controls.AddAt(0,div);

                createJSLinks();

                string sceneSource = SPContext.Current.Site.RootWeb.Url + "/_layouts/CodePlex/SlideshowWebPart/Scene.xml";
                div.Text =
                        "<script id=\"" + this.LibraryName.Replace(" ", string.Empty) + "Slides\" type=\"text/xml\"> " + Environment.NewLine +
                            "<?xml version=\"1.0\"?> " + Environment.NewLine +
                            "<slides baseUrl=\"\"> " + Environment.NewLine +
                                createSlidesXml() +
                            "</slides> " + Environment.NewLine +
                        "</script>" + Environment.NewLine +
                        "<div id=\"slideshow" + this.ID + "\"> " + Environment.NewLine +
                            "<script type=\"text/javascript\"> " + Environment.NewLine +
                                "createSlideshow('" + sceneSource + "', 'slideshow" + this.ID + "', { " + Environment.NewLine +
                                    "width: '" + slideshowWidth + "', " + Environment.NewLine +
                                    "height: '" + slideshowHeight + "', " + Environment.NewLine +
                                    "slidesSource: '#" + this.LibraryName.Replace(" ", string.Empty) + "Slides', " + Environment.NewLine +
                                    "background: '" + backgroundColor + "', " + Environment.NewLine +
                                    "buttonBackground: '" + buttonBackground + "', " + Environment.NewLine +
                                    "buttonForeground: '" + buttonForeground + "', " + Environment.NewLine +
                                    "buttonBorderColor: '" + buttonBorderColor + "', " + Environment.NewLine +
                                    "buttonPlayForeground: '" + buttonPlayForeground + "', " + Environment.NewLine +
                                    "captionBackground: '" + captionBackground + "', " + Environment.NewLine +
                                    "captionFontFamily: '" + captionFontFamily + "', " + Environment.NewLine +
                                    "captionFontSize: " + captionFontSize + ", " + Environment.NewLine +
                                    "captionFontStyle: '" + captionFontStyle + "', " + Environment.NewLine +
                                    "captionFontWeight: '" + captionFontWeight + "', " + Environment.NewLine +
                                    "captionOpacity: " + captionOpacity + ", " + Environment.NewLine +
                                    "contentBackground: '" + contentBackground + "', " + Environment.NewLine +
                                    "selectedThumbnailBorderColor: '" + selectedThumbnailBorderColor + "', " + Environment.NewLine +
                                    "trackerForeground: '" + trackerForeground + "', " + Environment.NewLine +
                                    "trackerFontFamily: '" + trackerFontFamily + "', " + Environment.NewLine +
                                    "trackerFontSize: " + trackerFontSize + ", " + Environment.NewLine +
                                    "trackerFontStyle: '" + trackerFontStyle + "', " + Environment.NewLine +
                                    "trackerFontWeight: '" + trackerFontWeight + "', " + Environment.NewLine +
                                    "borderRadius: " + borderRadius + ", " + Environment.NewLine +
                                    "padding: " + padding + ", " + Environment.NewLine +
                                    "captionVisible: " + captionVisible.ToString().ToLower() + ", " + Environment.NewLine +
                                    "thumbnailsVisible: " + thumbnailsVisible.ToString().ToLower() + ", " + Environment.NewLine +
                                    "trackerVisible: " + trackerVisible.ToString().ToLower() + ", " + Environment.NewLine +
                                    "buttonOptions: " + createButtonOptionsString() + ", " + Environment.NewLine +
                                    "autoPlay: " + autoPlay.ToString().ToLower() + ", " + Environment.NewLine +
                                    "slideSettings: { " + Environment.NewLine +
                                    "theme: " + theme + ", " + Environment.NewLine +
                                    "speedRatio: " + speedRatio + " " + Environment.NewLine +
                                    "}" + Environment.NewLine +
                            "});" + Environment.NewLine +
                            "</script>" + Environment.NewLine +
                        "</div>";              
            }
        }

        protected override void Render(HtmlTextWriter writer)
        {
            if (!this.DesignMode)
                base.Render(writer);
        }

        private void createJSLinks()
        {
            SPWeb web = SPContext.Current.Web;

            // Add style sheet to parent page 
            string js1 = web.Url + @"/_layouts/CodePlex/SlideshowWebPart/Silverlight.js";
            createJSLink(js1);

            string js2 = web.Url + @"/_layouts/CodePlex/SlideshowWebPart/SilverlightSpy.js";
            createJSLink(js2);

            string js3 = web.Url + @"/_layouts/CodePlex/SlideshowWebPart/Slide.js";
            createJSLink(js3);

            string js4 = web.Url + @"/_layouts/CodePlex/SlideshowWebPart/Slideshow.js";
            createJSLink(js4);

            string js5 = web.Url + @"/_layouts/CodePlex/SlideshowWebPart/SlideshowCreate.js";
            createJSLink(js5);
        }


        private void createJSLink(string js)
        {
            LiteralControl lc = new LiteralControl();
            lc.Text = "<script type=\"text/javascript\" src=\"" + js + "\"></script>";

            if (this.Page.Header != null)
                this.Page.Header.Controls.Add(lc);
        }

        private string createSlidesXml()
        {
            string slidesXml = string.Empty;

            SPWeb web = SPContext.Current.Web;

            try
            {
                foreach (SPListItem image in web.Lists[libraryName].Items)
                {
                    slidesXml += "<slide imageUrl='" + image["EncodedAbsWebImgUrl"] + "' thumbnailUrl='" + image["EncodedAbsThumbnailUrl"] + "' caption='" + image["Title"] + "'/>" + Environment.NewLine;
                }
            }
            catch
            {
                // libraryName was not found.
            }

            return slidesXml;
       }

       private string createButtonOptionsString()
       {

         StringBuilder sb = new StringBuilder();

         if(showPlayPauseButton)
         {
           WebPartTools.addDelimitedStringBuilderString(ref sb, BUTTON_PLAYPAUSE, BUTTON_DELIMITER);
         }

         if(showPrevNextButton)
         {
           WebPartTools.addDelimitedStringBuilderString(ref sb, BUTTON_PREVNEXT, BUTTON_DELIMITER);
         }

         if(showPrevNextPageButton)
         {
           WebPartTools.addDelimitedStringBuilderString(ref sb, BUTTON_PREVNEXTPAGE, BUTTON_DELIMITER);
         }

         if (showFullScreenButton)
         {
           WebPartTools.addDelimitedStringBuilderString(ref sb, BUTTON_FULLSCREEN, BUTTON_DELIMITER);
         }
         
         if (showSaveButton)
         {
           WebPartTools.addDelimitedStringBuilderString(ref sb, BUTTON_SAVE, BUTTON_DELIMITER);
         }

         return sb.ToString();

       }

    }
}